<g:if test="${!ajaxCall}">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="layout" content="mode" />
        <title>${Inter.printOut('Projects',session.language)}</title>
    </head>
    <body>
        <div class="undernav">
          <%
          def a = session.access
          a.refresh()
          %>
          <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
            <span class="menuButton"><g:link class="createProject" action="create">${Inter.printOut('New Project',session.language)}</g:link></span>
          </g:if>
           

            <!-- This is the help button. -->
            <%  def help = Help.findByNameAndLanguage("project_list", session.language)
            def helplink = createLink(action:'show', controller:'help', id: help?.id )%>
            <a href="#" class="menulink" onClick="MyWindow=window.open('${helplink}','Help','width=350,height=450'); return false;">${Inter.printOut('Help',session.language)}</a>
            <!-- This is the end of the help button. -->

        </div>

        <div class="body" style="width:98%">
          <g:link controller="project" action="updateBalance" class="urlUpdateBalance"></g:link>
</g:if>
            <h1>${Inter.printOut('Projects',session.language)}</h1>

            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <g:if test="${projectInstanceList.size() < 1}">
              <div class="message">There is no projects in the system yet.</div>
            </g:if>
            <g:else>
              <div class="list">
                  <table class="sortableTable" style="table-layout: fixed">
                      <thead>
                          <tr>
                            <th class="{sorter: 'link'}"><a href="#">${Inter.printOut('Activity Id',session.language)}</a>  </th>
                            <th class="{sorter: 'link'}"><a href="#">${Inter.printOut('name',session.language)}</a></th>
                           <!-- <th class="{sorter: 'link'}"><a href="#">${Inter.printOut('Area id',session.language)}</a></th> -->
                            <th class="{sorter: 'isoDate'}"><a href="#">${Inter.printOut('Start Date',session.language)}</a></th>
                            <th class="{sorter: 'isoDate'}"><a href="#">${Inter.printOut('End Date',session.language)}</a></th>
                            <th class="{sorter: 'text'}"><a href="#">Status</a></th>
                            <th width="10%" class="{sorter: 'numeric'}"><a href="#">${Inter.printOut('Current Balance',session.language)} (kr)</a></th>
                            <th width="10%" class="{sorter: 'numeric'}"><a href="#">${Inter.printOut('Incoming Balance',session.language)} (kr)</a></th>
                            <th width="10%" class="{sorter: 'numeric'}"><a href="#">${Inter.printOut('Outgoing Balance',session.language)} (kr)</a></th>

                          </tr>
                      </thead>
                      <tbody>

                      <g:each in="${projectInstanceList}" status="i" var="projectInstance">
                        
                        <g:if test="${ModeAccess.isAvailableInCurrentMode(session.mode,projectInstance.mode)}">
                          <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">

                              <td>
                                  <g:link action="show" id="${projectInstance?.id}">
                                   ${fieldValue(bean:projectInstance, field:'activityId')}
                                  </g:link>
                              </td>

                              <td>
                                  <g:link action="show" id="${projectInstance?.id}">
                                    ${fieldValue(bean:projectInstance, field:'name')}
                                  </g:link>
                              </td>

                             

                              <td>
                                 <g:formatDate date="${projectInstance.startDate}" format="yyyy-MM-dd"/>
                              </td>

                              <td>
                                <g:formatDate date="${projectInstance.endDate}" format="yyyy-MM-dd"/>
                              </td>

                              <td>
                              ${Inter.printOut(projectInstance.calcStatus(),session.language)}
                              </td>
                              <td>

                          <g:formatNumber number="${projectInstance.currentBudget().calculationResult()}" format="###"/>

                              </td>
                              <td>
                                <span class="balanceFigures" id="updateIncomingBalance" title="${projectInstance?.id}"><g:formatNumber number="${projectInstance.currentBudget().incomingBalance}" format="###" /> <img alt="edit" style="vertical-align:text-bottom;" src="${resource(dir:'images/skin',file:'pencil.png')}"/></span>
                              </td>
                              <td>
                                <g:formatNumber number="${projectInstance.currentBudget().calcOutgoingBalance()}" format="###" />
                              </td>
                          </tr>
                         </g:if>

                      </g:each>
                      </tbody>
                  </table>
              </div>
              
                <table class="resultTable" style="margin:0px; padding:5px;">
                  <tr>
                    <td width="63%">
                       ${Inter.printOut('Total balance',session.language)}:
                    </td
                    <td width="10%">
                      <g:formatNumber number="${Project.sumCalculationResultBudget(session)}" format="###"/>
                    </td>
                    <td width="10%">
                      <g:formatNumber number="${Project.calcTotalIncomingBalance(session)}" format="###" />
                    </td>
                    <td width="10%">
                      <g:formatNumber number="${Project.calcTotalOutgoingBalance(session)}" format="###" />
                    </td>
                  </tr>
                </table>
            
   </g:else>
<g:if test="${!ajaxCall}">
        </div>
    </body>
</html>

</g:if>
